package com.woniu.market_stall.mapper;

import com.woniu.market_stall.entity.Manager;
import com.woniu.market_stall.vo.ManagerVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ManagerMapper {
    int deleteByPrimaryKey(Integer id);
    @Update("update manager set is_delete = 1 where id =#{id} ")
    int deleteBPK(Integer id);


    int insert(Manager record);

    Manager selectByPrimaryKey(Integer id);

    List<Manager> selectAll();

    int updateByPrimaryKey(Manager record);

    @Select("select * from manager where name = #{name}")
    Manager selectByName(String name);


    List<ManagerVo> selectManagerByName(String name);

    void insertManager(ManagerVo managerVo);

    void insertRoleToManager(@Param("mid") Integer id, @Param("roleArr") int[] roleIds);

    @Select("select r.name from manager_url_role mr inner join role r on mr.role_id = r.id where mr.manager_id = #{id}")
    List<String> selectRoleNamesByMid(int mid);

    @Update("update manager set name = #{name},password=#{password},email=#{email},cellphone=#{cellphone},status=#{status},update_time=now(),dept_id=#{deptId} where id = #{id}")
    void update(ManagerVo managerVo);
    @Delete("delete from manager_url_role where manager_id = #{id}")
    void deleteRoleByMid(Integer id);

    void insertRoleByMid(@Param("mid") Integer id, @Param("list") List<Integer> list);

    @Update("update manager_url_role set is_delete = 1 where id = #{id}")
    void deleteManagerAndRoleByMid(Integer id);
//    @Delete("delete from manager_url_role where manager_id = #{id}")
//    void deleteManagerAndRoleByMid(Integer id);

    @Select("SELECT id FROM manager_dept WHERE dept_name=#{deptName}")
    Integer queryDeptId(String deptName);

    List<ManagerVo> selectAllManager();

}